<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:lxslt="http://xml.apache.org/xslt"
                xmlns:redirect="http://xml.apache.org/xalan/redirect"
                extension-element-prefixes="redirect">

    <!--
    Creates an all-classes.html file that contains a link to all files.
    -->
    <xsl:template match="checkstyle" mode="all.errors">
        <html>
            <head>
                <link rel="stylesheet" type="text/css" href="stylesheet.css"/>
            </head>
            <body>
                <h2>Errors</h2>
                <p>
                    <a href="summary.html" target="mainFrame">Summary</a>
                </p>
                <p>
                    <ul>
                        <xsl:apply-templates select="checktype" mode="all.checktype.errors">
                            <xsl:sort select="@type"/>
                        </xsl:apply-templates>
                    </ul>
                </p>
            </body>
        </html>
    </xsl:template>

    <xsl:template match="checktype" mode="all.checktype.errors">
        <xsl:variable name="fileCount" select="count(.//file)"/>
        <xsl:variable name="errorCount" select="count(.//error)"/>
        <li class="checktype">
            <a target="mainFrame">
                <xsl:attribute name="href">
                    <xsl:text>files/</xsl:text>
                    <xsl:value-of select="@type"/>
                    <xsl:text>.html</xsl:text>
                </xsl:attribute>
                <xsl:value-of select="@type"/>
            </a>
            (files: <xsl:value-of select="$fileCount"/>, errors: <xsl:value-of select="$errorCount"/>)
            <ul>
                <xsl:if test="count(//error[@severity='error'])>0">
                    <li><span class="error_category">error</span>
                        <ul>

                            <xsl:apply-templates select=".//error[@severity='error']" mode="list.error">
                                <xsl:sort select="@source"/>
                            </xsl:apply-templates>

                        </ul>
                    </li>
                </xsl:if>
                <xsl:if test="count(//error[@severity='warning'])>0">
                    <li><span class="error_category">warning</span>
                        <ul>

                            <xsl:apply-templates select=".//error[@severity='warning']" mode="list.error">
                                <xsl:sort select="@source"/>
                            </xsl:apply-templates>

                        </ul>
                    </li>
                </xsl:if>
                <xsl:if test="count(//error[@severity='info'])>0">
                    <li><span class="error_category">info</span>
                        <ul>

                            <xsl:apply-templates select=".//error[@severity='info']" mode="list.error">
                                <xsl:sort select="@source"/>
                            </xsl:apply-templates>

                        </ul>
                    </li>
                </xsl:if>
                <xsl:if test="count(//error[@severity='ignore'])>0">
                    <li><span class="error_category">ignore</span>
                        <ul>
                            <xsl:apply-templates select=".//error[@severity='ignore']" mode="list.error">
                                <xsl:sort select="@source"/>
                            </xsl:apply-templates>
                        </ul>
                    </li>
                </xsl:if>
            </ul>
        </li>
    </xsl:template>

    <xsl:template match="error" mode="list.error">
        <xsl:variable name="source" select="@source"/>

        <xsl:if test="count(preceding::error[@source=$source]) = 0">
            <li class="error">
                <a target="mainFrame">
                    <xsl:attribute name="href">
                        <xsl:text>files/</xsl:text>
                        <xsl:value-of select="@source"/>
                        <xsl:text>.html</xsl:text>
                    </xsl:attribute>

                    <xsl:value-of select="@source"/>
                </a> (files: <xsl:value-of select="count(//file[count(./error[@source=$source])>0])"/>)
            </li>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>